package com.peanut.baby.mvp.record;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import androidx.annotation.Nullable;

import com.peanut.baby.R;
import com.peanut.baby.model.RecordCategory;
import com.peanut.baby.mvp.BaseMvpActivity;
import com.peanut.baby.test.TestUtils;
import com.peanut.devlibrary.widget.TitleLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by anonymouslystudio on 2017/8/9.
 */

public class RecordActivity extends BaseMvpActivity
        implements TitleLayout.OnTitleClickListener,
        AdapterView.OnItemClickListener{
    @BindView(R.id.title)
    TitleLayout title;
    @BindView(R.id.record_category)
    GridView recordCategory;
    RecordCategoryGridAdapter   adapter;
    List<RecordCategory>        categories;

    public static void start(Context ctx) {
        ctx.startActivity(new Intent(ctx, RecordActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record);
        ButterKnife.bind(this);
        initViews();
        test();
    }

    private void initViews() {
        title.setTitle("诊疗记录");
        title.setOnTitleClickedListener(this);

        categories = new ArrayList<>();
        adapter = new RecordCategoryGridAdapter(this,categories);
        recordCategory.setAdapter(adapter);
        recordCategory.setOnItemClickListener(this);
    }

    private void test(){
        categories.addAll(TestUtils.getTestRecordCategories());
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onTitleBackClicked() {
        finish();
    }



    @Override
    public void onTitleRightClicked() {

    }

    @Override
    public void onTitleClicked() {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        //TODO remember to fix this
//        RecordEditActivity.start(this);
    }
}
